package com.terrence.sso.token.server.servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.terrence.sso.token.server.cache.SSOSessionCache;
import com.terrence.sso.token.server.vo.Token;

/**
 *
 * @author wuchuang
 *
 * 2017年3月8日 上午8:57:42
 * 
 * 
 */
public class SSOVerifyServlet extends HttpServlet {

    /**
	 * 
	 */
	private static final long serialVersionUID = -5812119434626963984L;

	@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	 String token = request.getParameter("token");
    	 System.out.println("ServerVerify : "+token);
    	 String validateTag = SSOSessionCache.contain(Token.getSessionIdFromToken(token)) ?"true":"false";
    	 //验证Token的有效性
         PrintWriter writer = response.getWriter();
         writer.write(validateTag);
    }

}